package com.ardf.util;

import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Paths;

public class ResourcePathUtil {
    public static String getResourcePath(String resource) throws URISyntaxException {
        URL resourceUrl = ResourcePathUtil.class.getClassLoader().getResource(resource);
        if (resourceUrl == null) {
            throw new IllegalArgumentException("Resource not found: " + resource);
        }
        return Paths.get(resourceUrl.toURI()).toString();
    }

    public static void main(String[] args) {
        try {
            // 获取resources根目录的路径
            String resourcesPath = getResourcePath("");
            System.out.println("Resources directory path: " + resourcesPath);

            // 获取resources目录下某个文件的路径
            String specificFilePath = getResourcePath("templates/downloadTemplate.xlsx");
            System.out.println("Specific file path: " + specificFilePath);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
